﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.bidsupplyinfo
{
    public partial class Modify : Web.Admin.BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int bsid = (Convert.ToInt32(Request.Params["id"]));
                    lcs.BLL.pmtypeinfo pmbll = new BLL.pmtypeinfo();
                    DataSet ds = pmbll.GetList("pmid>0");
                    ddlmtype.DataSource = ds;
                    ddlmtype.DataTextField = "pmtype";
                    ddlmtype.DataValueField = "pmid";
                    ddlmtype.DataBind();
                    ShowInfo(bsid);
                }
                Page.DataBind();
            }
        }

        private void ShowInfo(int bsid)
        {
            lcs.BLL.bidsupplyinfo bll = new lcs.BLL.bidsupplyinfo();
            lcs.Model.bidsupplyinfo model = bll.GetModel(bsid);
            this.lblbsid.Text = model.bsid.ToString();
            this.ddlmtype.SelectedValue = model.mtype.ToString();
            this.txtquota.Text = model.quota.ToString();
            this.txtsid.Text = model.sname;
            this.txtblevel.Text = model.blevel.ToString();
            hfsid.Value = model.sid.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (!PageValidate.IsDecimal(txtquota.Text))
            {
                strErr += "配额格式错误！\\n";
            }
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int bsid = int.Parse(this.lblbsid.Text);
            int mtype = int.Parse(this.ddlmtype.SelectedValue.ToString());
            decimal quota = decimal.Parse(this.txtquota.Text);
            int sid = 0;
            if (hfsid.Value != "") sid = int.Parse(hfsid.Value);
            int blevel = int.Parse(this.txtblevel.Text);
            if (sid != 0)
            {
                lcs.Model.bidsupplyinfo model = new lcs.Model.bidsupplyinfo();
                model.bsid = bsid;
                model.mtype = mtype;
                model.quota = quota;
                model.sid = sid;
                model.blevel = blevel;
                lcs.BLL.bidsupplyinfo bll = new lcs.BLL.bidsupplyinfo();
                bll.Update(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "没有找到供应商！");
            }

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
